package cn.schoolwow.workflow.test.module.analyzeWorkReport.audit.multiple.flow;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.workflow.QuickWorkFlow;
import cn.schoolwow.workflow.domain.instance.WorkFlowInstanceQuery;
import cn.schoolwow.workflow.domain.instance.WorkFlowInstanceStatus;
import cn.schoolwow.workflow.entity.WorkFlowInstance;
import org.junit.Assert;

import java.util.List;

public class CheckMultipleAuditResultFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        QuickWorkFlow quickWorkFlow = flowContext.checkInstanceData(QuickWorkFlow.class);
        int total = flowContext.checkData("total", int.class);

        int half = total/2;

        {
            WorkFlowInstanceQuery workFlowInstanceQuery = new WorkFlowInstanceQuery();
            workFlowInstanceQuery.statusList.add(WorkFlowInstanceStatus.Finished.status);
            List<WorkFlowInstance> passList = quickWorkFlow.getWorkFlowInstanceList(workFlowInstanceQuery);
            Assert.assertEquals(half, passList.size());
        }
        {
            WorkFlowInstanceQuery workFlowInstanceQuery = new WorkFlowInstanceQuery();
            workFlowInstanceQuery.statusList.add(WorkFlowInstanceStatus.Reject.status);
            List<WorkFlowInstance> rejectList = quickWorkFlow.getWorkFlowInstanceList(workFlowInstanceQuery);
            Assert.assertEquals(half, rejectList.size());
        }
    }

    @Override
    public String name() {
        return "分析工作报告-工作流批量提交-检查批量审批结果";
    }

}
